package com.controller;

import com.entity.*;
import com.group.SupplierAddGroup;
import com.group.SupplierModifyGroup;
import com.service.OrderService;
import com.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/supplier")
public class SupplierController {
    @Autowired
    private SupplierService supplierService;
    @RequestMapping("/getAll/{pageIndex}/{pageSize}")
    public Result<PageBean<Supplier>> getAll(
          @PathVariable("pageIndex") Integer pageIndex,
          @PathVariable("pageSize") Integer pageSize,
          @RequestBody Supplier supplier
    ){
        PageBean<Supplier> pageBean = supplierService.getAll(pageIndex, pageSize, supplier);
        return Result.ok(pageBean);
    }

    @RequestMapping("/findAll")
    public Result<List<Supplier>> findAll(){
        return Result.ok(supplierService.findAll());
    }


    //增加
    @PostMapping("/add")
    public Result add(@Validated(SupplierAddGroup.class) @RequestBody Supplier supplier){
        supplierService.add(supplier);
        return Result.ok();
    }

    @PostMapping("/getnumPurReqAndSupplierBySid/{sid}")
    public Result getnumPurReqAndSupplierBySid(@RequestBody @PathVariable("sid") int sid){
        return Result.ok(supplierService.getnumPurReqAndSupplierBySid(sid));
    }

    //通过eid删除
    @RequestMapping("/removeBySid/{sid}")
    public Result removeBySid(@PathVariable("sid")int sid){
        supplierService.removeBySid(sid);
        return Result.ok();
    }

    //修改供应商信息，并显示更新信息的时间
    @PostMapping("/modify")
    public Result modify(@Validated(SupplierModifyGroup.class)  @RequestBody Supplier supplier){
        supplierService.update(supplier);
        return Result.ok();
    }

}
